package com.senta.elasticsearch.service.impl;

import com.senta.elasticsearch.entity.BillingItemDis;
import com.senta.elasticsearch.repository.BillingItemDisRepository;
import com.senta.elasticsearch.service.EsBillingItemDisService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author anyang
 * Email: 1300378587@qq.com
 * Created Date:2019-11-20 09:15
 */
@Service
public class EsBillingItemDisServiceImpl implements EsBillingItemDisService{

    @Autowired
    BillingItemDisRepository billingItemDisRepository;

    @Override
    public boolean updateById(BillingItemDis billingItemD){
        String id = billingItemD.getPk();
        if(id != null){
            billingItemDisRepository.save(billingItemD) ;
        }
        return false;
    }

    @Override
    public boolean insert(BillingItemDis billingItemDis){
        if(billingItemDis==null){
            return false;
        }
        billingItemDisRepository.save(billingItemDis);
        return true;
    }

    @Override
    public boolean deleteById(String id){
         if(StringUtils.isBlank(id)) return false;
        billingItemDisRepository.deleteById(id);
        return true;
    }

    @Override
    public BillingItemDis selectById(String id){
        if(StringUtils.isBlank(id)) return null;
        Optional<BillingItemDis> byId = billingItemDisRepository.findById(id);
        return byId.get();
    }

    @Override
    public List<BillingItemDis> selectList(){
        return (List<BillingItemDis>)billingItemDisRepository.findAll();
    }

    @Override
    public boolean batchSave(List<BillingItemDis> list){
         if(list == null || list.size()==0){
               return false;
         }
        billingItemDisRepository.saveAll(list);
        return true;
    }

    @Override
    public boolean batchDel(List<BillingItemDis> list){
         if(list == null || list.size()==0){
            return false;
         }
         billingItemDisRepository.deleteAll(list);
         return true;
    }
}
